package com.shajj.movie;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class ShajjUtil {

	private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");

	static {
		FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+8"));
	}

	public static String replace(String source) {
		return source.replaceAll("[W|w]hat a fucking day[!|！]?", " 真是个傻鸡鸡！").replaceAll("CD", "ShaJJ").replaceAll("cd", "shajj").replaceAll("草蛋", "傻鸡鸡");
	}

	public static String DateFormat(Date date) {
		return FORMAT.format(date);
	}

	public static String getTimestamp(Date date) {
        String ret = "0秒钟之前";
        try {
            Long current = System.currentTimeMillis();
            Long tlong = (current - date.getTime()) / 1000;
            if (tlong < 0) {
                ret = "0秒钟之前";
            }
            if (tlong > 0 && tlong < 60) {
                ret = tlong + "秒钟之前";
            }
            if (tlong >= 60 && tlong < (60 * 60)) {
                ret = tlong / 60 + "分钟之前";
            }
            if (tlong >= (60 * 60) && tlong < (60 * 60 * 24)) {
                ret = tlong / (60 * 60) + "小时之前";
            }
            if (tlong >= (60 * 60 * 24) && tlong < (60 * 60 * 24 * 30)) {
                ret = tlong / (60 * 60 * 24) + "天之前";
            }
            if (tlong >= (60 * 60 * 24 * 30) && tlong < (60 * 60 * 24 * 30 * 6)) {
                ret = tlong / (60 * 60 * 24 * 30) + "个月以前";
            }
            if (tlong >= (60 * 60 * 24 * 30 * 6) && tlong < (60 * 60 * 24 * 30 * 12)) {
                ret = "半年以前";
            }
            if (tlong >= (60 * 60 * 24 * 30 * 12)) {
                ret = tlong / (60 * 60 * 24 * 30 * 12) + "年以前";
            }
        } catch (Exception ex) {
        }
        return ret;

    }

}
